<?php

namespace App\Service\Moment;

use App\Constants\ErrorCode;
use App\Model\Moment;
use App\Model\MomentComment;
use App\Service\BaseService;

/**
 * 动态评论删除
 */
class MomentCommentDelService extends BaseService
{
    public function handle()
    {
        $commentId = $this->request->input('comment_id', 0);
        if (!$commentId) return $this->setError(ErrorCode::PARAMETER_ERROR);
        $comment = MomentComment::find($commentId);
        $userId = $this->getUserId();
        if (!$userId || !$comment || $comment->user_id != $userId) {
            return $this->setError(ErrorCode::OP_NOT_VALID, '操作不合法，无法删除该留言！');
        }
        $ret = MomentComment::where('id', $commentId)->update(['flag' => MomentComment::STATUS_DEL]);
        //修改动态表comment_num字段
        Moment::updateCommentNum($comment->moment_id, -1);
        return ['result' => 1];
    }
}
